from lxml import etree

xml = '''<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:sayHelloResponse xmlns:ns2="http://impl.service.su.com/">
      <return>Hi suyanchao</return>
    </ns2:sayHelloResponse>
  </S:Body>
</S:Envelope>'''

# 注册命名空间
namespaces = {
    "S": "http://schemas.xmlsoap.org/soap/envelope/",
    "ns2": "http://impl.service.su.com/"
}

# 解析 XML
root = etree.fromstring(xml.encode())

# 使用 XPath 提取内容
result = root.xpath(
    "/S:Envelope/S:Body/ns2:sayHelloResponse/return/text()",
    namespaces=namespaces
)

print(result)  # 输出：['Hi suyanchao']
print(type(result))  # 输出：<class 'list'>
print(result[0])  # 输出：Hi suyanchao
